package com.fms.gui.templateCreator.components.date.parts;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BackDrop
{
	private int	diameter;
	
	private BufferedImage  buffer;

	public BackDrop(int _diameter)
	{
		this.diameter = _diameter;
		buffer = new BufferedImage(diameter + 1, diameter + 1, BufferedImage.TYPE_INT_ARGB);
		
		Graphics2D g2d = buffer.createGraphics();

		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                   			 RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setPaint(Color.black);
		g2d.translate(((int)(diameter/2.0)), ((int)(diameter/2.0)));
		g2d.drawOval(((int)(0 - diameter/2.0)), ((int)(0 - diameter/2.0)), diameter, diameter);
		

		List<String> numbers = new ArrayList<String>();
		numbers.add("12");
		numbers.add("1");
		numbers.add("2");
		numbers.add("3");
		numbers.add("4");
		numbers.add("5");
		numbers.add("6");
		numbers.add("7");
		numbers.add("8");
		numbers.add("9");
		numbers.add("10");
		numbers.add("11");
		
		Iterator<String> currentNumber = numbers.iterator();
		Font font = new Font("SansSerif", Font.BOLD, 14);
		g2d.setFont(font);
		FontMetrics m = g2d.getFontMetrics();
		for(double d = 0; d < ((Math.PI * 2) - 0.001); d += Math.PI/6)
		{
			double rotate = d - Math.PI/2.0;
			String value = currentNumber.next();
			g2d.transform(AffineTransform.getRotateInstance(rotate));
			g2d.translate(_diameter * 0.43, 0);
			g2d.transform(AffineTransform.getRotateInstance(-rotate));
			g2d.drawString(value, (int)(-m.stringWidth(value)/2.0), (int)(m.getHeight()/3.0));
			g2d.transform(AffineTransform.getRotateInstance(rotate));
			g2d.translate(-_diameter * 0.43, 0);
			g2d.transform(AffineTransform.getRotateInstance(-rotate));			
		}
		
		for(double d = 0; d < ((Math.PI * 2) - 0.001); d += Math.PI/6)
		{
			double rotate = d - Math.PI/2.0;
			g2d.transform(AffineTransform.getRotateInstance(rotate));
			g2d.translate(_diameter * 0.5, 0);
			g2d.drawLine(0, 0, -7, 0);
			g2d.translate(-_diameter * 0.5, 0);
			g2d.transform(AffineTransform.getRotateInstance(-rotate));			
		}
		
	}
	
	public void paint(Graphics g)
	{
		Graphics2D g2d = (Graphics2D)g;
		g2d.drawImage(buffer,((int)(0 - diameter/2.0)), ((int)(0 - diameter/2.0)), null);
		
	}
}
